package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Gathering;
import cn.wolfcode.crm.query.GatheringQueryObject;
import cn.wolfcode.crm.service.IGatheringService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("gathering")
public class GatheringController {
    @Autowired
    private IGatheringService gatheringService;

    @RequestMapping("view")
    public String query() {
        return "/studentmanagement/gathering";
    }


    @RequestMapping("list")
    @ResponseBody
    public PageResult list(GatheringQueryObject qo){
        return gatheringService.getAll(qo);
    }

    @RequestMapping("saveOrUpdate")
    public JSONResult saveOrUpdate(Gathering gathering){
        JSONResult jsonResult = new JSONResult();
        gatheringService.saveOrUpdate(gathering);
        return jsonResult;
    }


    @RequestMapping("audit")
    @ResponseBody
    public JSONResult audit(long id){
        JSONResult jsonResult = new JSONResult();
        try {
            gatheringService.audit(id);
            return jsonResult;
        }catch (Exception e){
            jsonResult.remark(e.getMessage());
            return jsonResult;
        }
    }


    @RequestMapping("rem")
    @ResponseBody
    public JSONResult rem(long id){
        JSONResult jsonResult = new JSONResult();
        try {
            gatheringService.delete(id);
            return jsonResult;
        }catch (Exception e){
            jsonResult.remark(e.getMessage());
            return jsonResult;
        }
    }
}
